from django.db import models
from django.contrib.auth.models import User

LAYOUT_CHOICES=(("page_layout_single.html","Single image"),
                ("page_layout_double.html","Two images"),
                ("page_layout_four_a_page.html","Four images"),
                ("page_layout_six_a_page.html","Six images"),
                ("page_layout_twelve_a_page.html","Twelve images"),)

# Create your models here.
class Page(models.Model):
    layout = models.CharField(max_length=32,choices=LAYOUT_CHOICES)
    caption=models.CharField(max_length=128)
    extra_caption=models.CharField(max_length=128)
    description = models.TextField()
    album = models.ForeignKey('Album', blank=True,null=True)
    
    def get_pictures(self):
        return Picture.objects.filter(page = self)
    
    class Meta:
        ordering = ['id']
    
class Picture(models.Model):
    owner = models.ForeignKey(User)
    uri = models.CharField(max_length=256)
    name = models.CharField(max_length=64)
    description = models.TextField()
    pages = models.ManyToManyField(Page, blank=True, null=True)
    
    def __unicode__(self):
        return self.name


class Album(models.Model):
    name = models.CharField(max_length=64)
    owner = models.ForeignKey(User)
    public = models.BooleanField()
    description = models.TextField()
    public_token = models.CharField(max_length=32, blank=True)
    cover_picture = models.ForeignKey(Picture, blank=True)
    
    class Meta:
        ordering = ['id']
    
